package org.dreamland.infrastructure.security

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.GrantedAuthority

/**
 * @author DYM
 * @date 2024/5/8 14:53
 */
class UsernamePasswordCaptchaAuthenticationToken : UsernamePasswordAuthenticationToken {
    /**
     * 人机验证码
     */
    val captcha: String

    constructor(principal: Any?, credentials: Any?, captcha: String) : this(principal, credentials, emptyList<GrantedAuthority?>(), captcha)

    constructor(principal: Any?, credentials: Any?, authorities: Collection<GrantedAuthority?>?, captcha: String) : super(principal, credentials, authorities) {
        this.captcha = captcha
    }

    companion object {
        fun unauthenticated(principal: Any?, credentials: Any?, captcha: String): UsernamePasswordCaptchaAuthenticationToken {
            return UsernamePasswordCaptchaAuthenticationToken(principal, credentials, captcha)
        }
    }
}
